

class P384_39643 {

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		
		System.out.println("SLURPYS OUTPUT");
		for (int k = 0; k < cases; k++) {
			process(readLn());
		}
		System.out.println("END OF OUTPUT");
	}
	
	private static void process(String line) {
		
		
		for (int k = 1; k < line.length(); k++) {
			String s1 = line.substring(0, k);
			String s2 = line.substring(k);
//			System.out.println("----");
//			System.out.println("isSlimp(s1) " + s1 + " - " + isSlimp(s1));
//			System.out.println("isSlump(s2) " + s2 + " - " + isSlump(s2));
			
			
			if (isSlimp(s1) && isSlump(s2)) {
				System.out.println("YES");
				return;
			}
			
		}
		
		System.out.println("NO");
	}

	private static boolean isSlump(String s1) {
		
		if (s1.length() < 2) return false;
		
		if (!(s1.charAt(0) == 'D' || s1.charAt(0) == 'E')){
			return false;
		}
		
		
		if (s1.charAt(1) != 'F') return false;
		
		
		for (int k = 2; k < s1.length(); k++) {
			if (s1.charAt(k) != 'F') {
				String s3 = s1.substring(k);
				if (isSlump(s3) || "G".equals(s3)) return true;
				else return false;
			}
			
		}
		
		// TODO Auto-generated method stub
		return false;
	}

	private static boolean isSlimp(String s1) {
//		System.out.println("s1: " + s1);
		
		if (s1.length() < 2) return false;
		
		if (s1.charAt(0) != 'A') {
			return false;
		}
		
		if (s1.length() == 2 && s1.charAt(1) == 'H') return true;
		if (s1.length() == 2 && s1.charAt(1) != 'H') return false;
		
		
		
		if (s1.charAt(1) == 'B' && isSlimp(s1.substring(2, s1.length() - 1) ) && s1.charAt(s1.length() - 1) == 'C')
			return true;
		
		if (isSlump(s1.substring(1, s1.length() - 1) ) && s1.charAt(s1.length() - 1) == 'C')
			return true;
			
		return false;
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuilder buffer = new StringBuilder();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char) car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
                System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) {
            return (null);
        }
        if ((car < 0) && (buffer.length() == 0))
            return (null);
        return (buffer.toString()).trim();
    }
	
}
